import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:testlzhu/common/routers/app_pages.dart';
import 'package:testlzhu/common/routers/app_routers.dart';
import 'package:testlzhu/common/service/myservice.dart';
import 'package:testlzhu/data/common_net.dart';
import 'package:testlzhu/data/net/my_interceptor.dart';
import 'package:testlzhu/view/custom_animation.dart';
import 'data/net/http_manager.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

void main() async {
  HttpManager().setBaseUrl(CommonNet.apiHostLezhu).setConnectTimout(3000).setReceiveTimeout(3000).addIntercept(MyInterceptor());
  if (Platform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }


  initServices();

  runApp(const MyApp());
  configLoading();
}




/// 在你运行Flutter应用之前，让你的服务初始化是一个明智之举。
// 因为你可以控制执行流程（也许你需要加载一些主题配置，apiKey，由用户自定义的语言等，所以在运行ApiService之前加载SettingService。
///所以GetMaterialApp()不需要重建，可以直接取值。
void initServices() async {
  print('starting services ...');
  ///这里是你放get_storage、hive、shared_pref初始化的地方。
  ///或者moor连接，或者其他什么异步的东西。
  await Get.putAsync(() => MyService().init());
  print('All services started...');
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      getPages: AppPages.routes,
      debugShowCheckedModeBanner: false,
      title: "asdasdsa",
      enableLog: true,
      initialRoute: AppRoutes.splash,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),

      builder: EasyLoading.init(),
      // home: const MyHomePage(title: 'Flutter Demo Home Page'),
      // home: SplashPageWidget(),
      // home: textAa(),
    );
  }


}

void configLoading() {
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 2000)
    ..indicatorType = EasyLoadingIndicatorType.fadingCircle
    ..loadingStyle = EasyLoadingStyle.dark
    ..indicatorSize = 45.0
    ..radius = 10.0
    ..progressColor = Colors.yellow
    ..backgroundColor = Colors.green
    ..indicatorColor = Colors.yellow
    ..textColor = Colors.yellow
    ..maskColor = Colors.blue.withOpacity(0.5)
    ..userInteractions = true
    ..dismissOnTap = false
    ..customAnimation = CustomAnimation();
}